/
GregorianCalendar.php
71 lines (58 loc) 路 1.44 KB
/
GregorianCalendar.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
declare(strict_types=1);
namespace Aeon\Calendar\Gregorian;
/**
* @psalm-immutable
*/
final class GregorianCalendar implements Calendar
{
private TimeZone $timeZone;
public function __construct(TimeZone $timeZone)
{
$this->timeZone = $timeZone;
}
/**
* @psalm-pure
*/
public static function UTC() : self
{
return new self(TimeZone::UTC());
}
/**
* @psalm-pure
* @psalm-suppress ImpureFunctionCall
*/
public static function systemDefault() : self
{
return new self(TimeZone::fromString(\date_default_timezone_get()));
}
public function timeZone() : TimeZone
{
return $this->timeZone;
}
public function currentYear() : Year
{
return Year::fromDateTime($this->now()->toDateTimeImmutable());
}
public function currentMonth() : Month
{
return Month::fromDateTime($this->now()->toDateTimeImmutable());
}
public function currentDay() : Day
{
return Day::fromDateTime($this->now()->toDateTimeImmutable());
}
public function now() : DateTime
{
return DateTime::fromDateTime(new \DateTimeImmutable('now', new \DateTimeZone('UTC')))
->toTimeZone($this->timeZone);
}
public function yesterday() : DateTime
{
return $this->now()->yesterday();
}
public function tomorrow() : DateTime
{
return $this->now()->tomorrow();
}
}